package org.takeback.chat.lottery.listeners;

import org.springframework.stereotype.Component;
import org.takeback.chat.entity.Message;
import org.takeback.chat.lottery.Lottery;
import org.takeback.chat.lottery.LotteryDetail;
import org.takeback.chat.store.room.LotteryFactory;
import org.takeback.chat.store.room.Room;
import org.takeback.chat.store.user.User;
import org.takeback.chat.utils.MessageUtils;

@Component("G06")
public class G06 extends DefaultGameListener {
	public boolean onBeforeRed(LotteryFactory.DefaultLotteryBuilder builder) throws GameException {
		return true;
	}

	public void onRed(LotteryFactory.DefaultLotteryBuilder builder) throws GameException {
	}

	public void onFinished(Lottery lottery) throws GameException {
	}

	public void processExpireEvent(Lottery lottery) throws GameException {
		super.processExpireEvent(lottery);
	}

	public boolean onBeforeOpen(Integer uid, Lottery lottery) throws GameException {
		return true;
	}

	public void onOpen(Lottery lottery, LotteryDetail lotteryDetail) throws GameException {
		Integer owner = lottery.getSender();
		User ou = (User) this.userStore.get(owner);

		Integer getter = lotteryDetail.getUid();
		User gu = (User) this.userStore.get(getter);

		String txt = gu.getUserId() + "拆开" + ou.getUserId() + "的挑战书,日后再见休怪刀剑无情!";
		Message msg = new Message("TXT_SYS", Integer.valueOf(0), txt);
		Room room = (Room) this.roomStore.get(lottery.getRoomId());
		MessageUtils.broadcast(room, msg);
	}

	public void processStartEvent(Room room) throws GameException {
		super.processStartEvent(room);
	}

	public boolean onBeforeStart(Room room) throws GameException {
		return true;
	}
}
